// Import some needed classes
import sun.net.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.*;

public class ServerConnector {

	public static void main(String[] args) {
		TCPush();

	}

	// public static void AisPush() {
	//
	// byte[] send_data = new byte[1024];
	//
	// DatagramSocket socket;
	// try {
	// socket = new DatagramSocket();
	//
	// InetAddress IPAddress = InetAddress.getByName("192.168.204.68");
	//
	// String data = "AIS MESSAGEEEE";
	//
	// send_data = data.getBytes();
	//
	// DatagramPacket send_packet = new DatagramPacket(send_data,
	// send_data.length, IPAddress, 12347);
	//
	// socket.send(send_packet);
	//
	// socket.close();
	//
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }
	//
	// public static void aisBroadcast() {
	//
	// // Which port should we send to
	// int port = 12348;
	// // Which address
	// // String group = "225.4.5.6";
	// // Which ttl
	// int ttl = 1;
	// // Create the socket but we don't bind it as we are only going to send
	// // data
	// DatagramSocket s;
	// try {
	// s = new DatagramSocket();
	//
	// InetAddress IPAddress = InetAddress.getByName("192.168.204.68");
	//
	// // Note that we don't have to join the multicast group if we are
	// // only
	// // sending data and not receiving
	// // Fill the buffer with some data
	//
	// String ais = "AIS message";
	// // byte[] buf = new byte[10];
	// // for (int i = 0; i < buf.length; i++)
	// // buf[i] = (byte) i;
	//
	// // Create a DatagramPacket
	// DatagramPacket pack = new DatagramPacket(ais.getBytes(),
	// ais.length(), IPAddress, port);
	// // Do a send. Note that send takes a byte for the ttl and not an
	// // int.
	// s.send(pack);
	//
	// System.out.print("--------------------");
	// // And when we have finished sending data close the socket
	// s.close();
	//
	// } catch (IOException e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }

	public static void TCPush() {
		Socket socket;
		String msg = " TCP AIS MESSAGE";

		try {
			socket = new Socket("192.168.204.114", 12347);

			System.out.println("AISPUSH.java--------------------------" + 2);

			// write to server
			OutputStream os = socket.getOutputStream();

			os.write(msg.getBytes(), 0, msg.length());
			System.out.println("AISPUSH.java--------------------------" + 3);

			// clearing msg to insert response msg from server.
			// msg = null;
			//
			// // read from server
			// InputStream input = myClient.getInputStream();
			// ObjectInputStream ois = new ObjectInputStream(input);
			// System.out
			// .println("AISPUSH.java--------------------------" + 4);
			// // msg = (ClientMessage) ois.readObject();
			// System.out
			// .println("AISPUSH.java--------------------------" + 5);
			os.close();
			os.close();
			// ois.close();
			// input.close();

		} catch (Exception e) {
			System.out.println(e);

		}

	}
}